<template>
  <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
    <el-form-item label="销售企业" prop="salesCompanyName">
      <el-input clearable :maxlength="50" v-model="queryParams.salesCompanyName" placeholder="请输入销售企业"
        @keyup.enter="handleQuery" class="!w-200px" />
    </el-form-item>
    <el-form-item label="采购企业" prop="purchaseCompanyName">
      <el-input clearable :maxlength="50" v-model="queryParams.purchaseCompanyName" placeholder="请输入采购企业"
        @keyup.enter="handleQuery" class="!w-200px" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleQuery">搜索</el-button>
      <el-button @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>
  <div class="flex justify-between py-12px">
    <div>
      <el-button type="primary" @click="openForm()" v-hasPermi="['mst:shortPriceConfig:create']">新增</el-button>
    </div>
  </div>
  <el-table v-loading="loading" :data="list" border stripe :header-cell-style="{ background: '#F3F4F7', color: '#555' }"
    class="pt-12px">
    <el-table-column label="销售企业" align="center" prop="salesCompanyName" min-width="200"
      :show-overflow-tooltip="true" />
    <el-table-column label="采购企业" align="center" prop="purchaseCompanyName" min-width="200"
      :show-overflow-tooltip="true" />
    <el-table-column label="短倒价格" align="center" prop="shortPrice" min-width="150" :show-overflow-tooltip="true" />
    <el-table-column label="创建时间" align="center" prop="createTime" width="200" :formatter="dateFormatter"
      :show-overflow-tooltip="true" />
    <el-table-column label="更新时间" align="center" prop="updateTime" width="200" :formatter="dateFormatter"
      :show-overflow-tooltip="true" />
    <el-table-column label="创建人" align="center" prop="operator" width="150" :show-overflow-tooltip="true" />
    <el-table-column label="操作" align="center" prop="quotationTime" width="100">
      <template #default="scope">
        <el-button link type="primary" @click="openForm(scope.row.id)" v-hasPermi="['mst:shortPriceConfig:update']">
          编辑
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
    @pagination="getList" />
  <inputForm ref="inputFormRef" @success="resetQuery"></inputForm>
</template>
<script setup lang="ts" name="enterpriseManage">
  import * as Utils from '@/utils/dict'
  import inputForm from './inputForm.vue'
  import * as coalMarket from '@/api/coalMarket'
  import { dateFormatter } from '@/utils/formatTime'

  const { DICT_TYPE, getIntDictOptions, getDictLabel } = reactive(Utils)
  const loading = ref(false) // 列表的加载中
  const total = ref(0) // 列表的总页数
  const list = ref([]) // 列表的数据
  const queryParams = ref({
    pageNo: 1,
    pageSize: 10,
    purchaseCompanyName: undefined,
    salesCompanyName: undefined,
  })
  const queryFormRef = ref()
  const inputFormRef = ref()

  /** 查询列表 */

  const getList = async () => {
    loading.value = true
    try {
      const data = await coalMarket.getShortPriceSettingPage(queryParams.value)
      list.value = data.list || []
      total.value = data.total || 0
    } finally {
      loading.value = false
    }
  }

  const openForm = (id) => {
    inputFormRef.value.open(id)
  }

  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.value.pageNo = 1
    getList()
  }

  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef.value.resetFields()
    handleQuery()
  }

  /** 初始化 **/
  onMounted(() => {
    getList()
  })
</script>